package wqh.controller.json;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import wqh.domain.XkDevice;
import wqh.domain.XkMonitorGeo;
import wqh.domain.XkSensorAlarm;
import wqh.domain.XkSensorAlarmLog;
import wqh.pojo.MapRet;
import wqh.service.XkMonitorGeoService;
import wqh.service.XkSensorAlarmLogService;
import wqh.service.XkSensorAlarmService;

/**
 * Created by wqh on 2017/1/13.
 */
@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/json/xk_device/sensor/alarm")
public class XkSensorAlarmJSON {

    @Autowired
    private XkSensorAlarmService xkSensorAlarmService;

    @Autowired
    private XkSensorAlarmLogService xkSensorAlarmLogService;

    @RequestMapping(value = "/confirm",method = RequestMethod.POST)
    public Object confirm(@RequestBody XkSensorAlarmLog x){
        try {
            if(x.getSensor_id() == null || x.getDevice_id() == null)  return MapRet.ERROR();
            xkSensorAlarmLogService.save(x);
            xkSensorAlarmService.deleteBySensorIdAndDeviceId(new XkSensorAlarm(x.getSensor_id(),x.getDevice_id()));
            return MapRet.SUCCESS();
        }catch (Exception e){
            e.printStackTrace();
            return MapRet.ERROR();
        }
    }

    @RequestMapping(value = "unconfirmed",method = RequestMethod.GET)
    public Object unconfirmed(){
        return MapRet.DATA(xkSensorAlarmService.findAll());
    }

    @RequestMapping(value = "confirmed",method = RequestMethod.GET)
    public Object confirmed(){
        return MapRet.DATA(xkSensorAlarmLogService.findAll());
    }

}
